import {applicationFormUrlEncodedHeader, applicationJsonHeader, doGet, doPost} from "@/net/axios-request.ts";
import {userTokenHeader} from "@/utils/auth-utils.ts";

export interface Category {
    categoryId: number,
    name: string,
    description: string,
    permission: string
}

export function getEmptyCategory(): Category {
    return { categoryId: 0, description: "", name: "", permission: "" }
}

export async function getAllCategory() {
    return (await doGet<Category[]>("/api/category/all", {}, {})).data
}

export async function deleteCategory(categoryId: number) {
    return await doPost("/api/category/delete", {...userTokenHeader(), ...applicationFormUrlEncodedHeader}, { categoryId: categoryId })
}

export async function saveOrUpdateCategory(category: Category) {
    return await doPost("/api/category/save", {...userTokenHeader(), ...applicationJsonHeader}, {...category})
}